package org.terramagnet.mvcframework.asynchronous.jdbc;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;

public class Update implements Serializable {

    private List<Serializable[]> args = new LinkedList<Serializable[]>();
    private String sql;
    private BatchPreparedStatementSetter batch;

    public Update(String sql) {
        this.sql = sql;
    }

    public List<Object[]> toArgs() {
        List<Object[]> rtnVal = new ArrayList<Object[]>(args);
        args = new LinkedList<Serializable[]>();
        return rtnVal;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public boolean isMultiple() {
        return args.size() > 1;
    }

    public boolean isBatched() {
        return batch != null;
    }

    public Update add(Serializable[] e) {
        args.add(e);
        return this;
    }

    public void setBatch(BatchPreparedStatementSetter batch) {
        this.batch = batch;
    }

    public BatchPreparedStatementSetter getBatch() {
        return batch;
    }

}
